﻿using System;
using Be.Timvw.Framework.Domain.Ranges;

namespace Be.Timvw.Framework.Domain.Effectivity
{
    public class Effectivity<T> : IEffectivity<T>
    {
        private readonly T element;
        private readonly IRange<DateTime> period;

        /// <summary>
        /// Initializes a new instance of the <see cref="Effectivity&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="period">The period.</param>
        public Effectivity(T element, IRange<DateTime> period)
        {
            this.element = element;
            this.period = period;
        }

        #region IEffectivity<T> Members

        /// <summary>
        /// Gets the element.
        /// </summary>
        /// <value>The element.</value>
        public T Element
        {
            get { return this.element; }
        }

        /// <summary>
        /// Gets the period.
        /// </summary>
        /// <value>The period.</value>
        public IRange<DateTime> Period
        {
            get { return this.period; }
        }

        /// <summary>
        /// Determines whether the element is effective on the given date.
        /// </summary>
        /// <param name="validityDate">The validity date.</param>
        /// <returns>
        /// 	<c>true</c> if [is effective on] [the specified validity date]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsEffectiveOn(DateTime validityDate)
        {
            return this.period.Includes(validityDate);
        }

        #endregion
    }
}